package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketAdmin;
import com.cskaoyan.bean.zhangshizhi.web.admin.PageBO;
import com.cskaoyan.bean.zhangshizhi.web.admin.*;
import com.cskaoyan.config.zhangshizhi.CountTime;
import com.cskaoyan.service.AdminService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理员管理
 *
 * @author little ants（张时智）
 * @since 2022/06/25 17:06
 */

@RestController
@RequestMapping("admin/admin")
public class AdminController {

    @Autowired
    AdminService adminService;

    @CountTime
    @RequiresPermissions(value = {"*", "admin:admin:list"}, logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo adminSelect(PageBO adminBO) {
        AdminListVO adminList = adminService.getAdminList(adminBO);
        return BaseRespVo.ok(adminList);
    }


    @CountTime
    @RequiresPermissions(value = {"*", "admin:admin:create"}, logical = Logical.OR)
    @RequestMapping("create")
    public BaseRespVo adminCreate(@RequestBody MarketAdmin marketAdmin) {
        adminService.createAdmin(marketAdmin);
        return BaseRespVo.ok();
    }


    @CountTime
    @RequiresPermissions(value = {"*", "admin:admin:update"}, logical = Logical.OR)
    @RequestMapping("update")
    public BaseRespVo adminUpdate(@RequestBody MarketAdmin marketAdmin) {
        AdminUpdateVO adminUpdateVO = adminService.updateAdmin(marketAdmin);
        return new BaseRespVo().ok(adminUpdateVO);
    }


    @CountTime
    @RequiresPermissions(value = {"*", "admin:admin:delete"}, logical = Logical.OR)
    @RequestMapping("delete")
    public BaseRespVo adminRemove(@RequestBody AdminDeleteBO adminDeleteBO) {
        adminService.removeAdmin(adminDeleteBO);
        return new BaseRespVo().ok();
    }

}
